<template>
  <div>
    <input type="text" v-model="kw">
    <button @click="click">click</button>
    <button @click="disconnect">disconnect</button>
  </div>
</template>

<script setup>
import { io } from "socket.io-client";
import { ref } from "vue"
const socket = io("http://localhost:3000", {
  autoConnect: true,
  query: {
    username: "张三"
  }
})
const kw = ref("");
const click = () => {
  socket.emit("sendMsg", kw.value)
}

const disconnect = () => {
  socket.disconnect()
}

socket.on('/api/getNow', function (msg) {
  console.log('接收消息', msg);
});

socket.on("heart", (msg) => {
  console.log('接收消息', msg);
})
</script>

<style lang="scss" scoped></style>